package com.hans.scala

import java.io.{PrintWriter, File}
import java.util.Date

object LazyExample {
  def main(args: Array[String]) {
    change("hello world.")
    def strDef = scala.io.Source.fromFile("data\\test.txt").mkString
    lazy val strLazy = scala.io.Source.fromFile("data\\test.txt").mkString
    val strVal = scala.io.Source.fromFile("data\\test.txt").mkString
    println("change test....")
    change("hello hans.")
    println(strVal)
    println(strLazy)
    println(strDef)
    println("\nchange again....")
    change("hello hans again.")
    println(strVal)
    println(strLazy)
    println(strDef)
  }

  def change(str: String) {
    val writer = new PrintWriter("data\\test.txt")
    try {
      writer.print(str)
    } finally {
      writer.close()
    }
  }
}
